package newcoder_exp.justPractise;

import org.junit.Test;

public class NC142 {
    public class Solution1 {

        public int solve (String a) {
            int len;
            if (a == null || (len = a.length()) == 0) {
                return 0;
            }
            for (int t = len / 2; t > 0; t--) {
                for (int i = 0; i + 2 * t <= len; i++) {
                    String s1 = a.substring(i, t + i);
                    String s2 = a.substring(t + i, i + 2 * t);
                    if (s1.equals(s2)) {
                        return 2 * t;
                    }
                }
            }
            return 0;
        }
    }
    public class Solution {

        //滑动窗口方法
        public int solve (String a) {
            int len;
            if (a == null || (len = a.length()) == 0) {
                return 0;
            }
            for (int t = len / 2; t > 0; t--) {
                for (int i = 0; i + 2 * t <= len; i++) {
                    String s1 = a.substring(i, t + i);
                    String s2 = a.substring(t + i, i + 2 * t);
                    if (s1.equals(s2)) {
                        return 2 * t;
                    }
                }
            }
            return 0;
        }
    }
    @Test
    public void test() {
        Solution s = new Solution();
        s.solve(
            "abcab"
            );

    }
}
